
#include "gmatlab.h"

// mxArray *g_irepository_matlab_find_symbol(gchar *ns, gchar *name);
void mexFunction(int nlhs, mxArray *lhs[], int nrhs, const mxArray *rhs[])
{
  gchar *ns, *name;

  // Check and convert arguments
  if (nrhs != 2) g_matlab_error("gmatlab:numArg", "g_irepository_matlab_find_symbol() takes 2 arguments");
  if (nlhs != 1) g_matlab_error("gmatlab:numRet", "g_irepository_matlab_find_symbol() has 1 return value");
  if (mxGetClassID(rhs[0]) != mxCHAR_CLASS) g_matlab_error("gmatlab:badType", "g_irepository_matlab_find_symbol() Arg 1 must be char, not %s", mxGetClassName(rhs[0]));
  if (mxGetClassID(rhs[1]) != mxCHAR_CLASS) g_matlab_error("gmatlab:badType", "g_irepository_matlab_find_symbol() Arg 2 must be char, not %s", mxGetClassName(rhs[1]));
  ns = g_matlab_mxArray_get_utf8(rhs[0]);
  g_matlab_cleanup_add(g_free, ns);
  name = g_matlab_mxArray_get_utf8(rhs[1]);
  g_matlab_cleanup_add(g_free, name);
  
  // Call function
  lhs[0] = g_irepository_matlab_find_symbol(ns, name);
  /* To allow re-entrance, don't use any escape or cleanup calls */
}
